package weavingdraft;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.WindowConstants;

import GUI.SubmitEntryGUI;

/**
 * Creates the WeavindDraftFrame object. 
 * @author Justin Wong. 
 *
 */
@SuppressWarnings("serial")
public class WeavingDraftFrame extends JFrame{
	
	
	/**
	  * This field is for the Border Layout that contains all my buttons
	  * for the release design stage.
	  */

	public SubmitEntryGUI my_release_panel;
	/**
	 * The WeavingDraft object to refer to. 
	 */
	
	public WeavingDraft draft;
	/**
	 * Creates the object of the WeavingDraftFrame. 
	 * @param my_entry
	 * @param the_draft
	 */
	
	public WeavingDraftFrame(SubmitEntryGUI my_entry, WeavingDraft the_draft) {

		my_release_panel = my_entry;
		draft = the_draft;
	}
	

	public void start(){
		
		Container pane = new Container();
		pane.setLayout(null);
		
		ThreadGrid thread = new ThreadGrid(draft);
		TieUpGrid tieup = new TieUpGrid(draft);
		PedalGrid pedal = new PedalGrid(draft);
		PatternGrid pattern = new PatternGrid(draft);
		
		pane.add(tieup);
		pane.add(thread);
		pane.add(pedal);
		pane.add(pattern);
		
		Dimension size = tieup.getPreferredSize();
		tieup.setBounds(1, 1, 120, 120);
		
		size = thread.getPreferredSize();
		thread.setBounds(125, 1, 480, 120);
		
		size = pedal.getPreferredSize();
		pedal.setBounds(1, 125, 120, 480);
		
		size = pattern.getPreferredSize();
		pattern.setBounds(125, 125, 480, 480);
		
		this.add(pane);
		
		JButton submit_button = new JButton("Submit");
		submit_button.addActionListener(new SubmitListener());
		JPanel panel = new JPanel(new BorderLayout());
		panel.add(submit_button, BorderLayout.EAST);
		this.add(panel, BorderLayout.SOUTH);
		
		this.setTitle("Weaving Draft");
		this.setVisible(true);
		this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		this.setSize(610, 660);
		this.setLocationRelativeTo(null);
		this.setResizable(false);
	}

	class SubmitListener implements ActionListener {

		/**
		 * Action performed method that displays the about message.
		 * @param the_event The event, ignored.
		 */

		@Override
		public void actionPerformed(final ActionEvent the_event) {
			
			my_release_panel.createReleaseGrid();
			dispose();
		}
	}
	/**
	 * Gets the weaving draft. 
	 * @return the draft pattern.
	 */
	public WeavingDraft getDraft(){
		return draft;
	}
}
